/**
 * 
 */
Ext.ns('Expr.ui');
Ext.form.Field.prototype.msgTarget = 'side';
test_patient_id='219556';
select_drug= null;
var tip_text = "关于不良反应/事件过程描述及处理情况的相关要求:<br/>"+
"一般分三段进行描述：<br/>"+
"1、出现ADR 的第一次描述：用药于ADR的间隔时间、症状、体征和相关检查.<br/>"+
"2、病情的动态变化：使用了什么治疗措施，结果的症状、体征和相关检查。<br/>"+
"3、治疗措施的治疗结果。<br/>"+
"简单的ADR可缺省第二项。<br/>"

Ext.ux.form.HtmlEditor.Image = Ext.extend(Ext.util.Observable, {
	// Image language text
	langTitle: '输入帮助',
    urlSizeVars: ['width','height'],
    basePath: 'image.php',
    init: function(cmp){
        this.cmp = cmp;
        this.cmp.on('render', this.onRender, this);
        this.cmp.on('initialize', this.onInit, this, {delay:100, single: true});
    },
    onEditorMouseUp : function(e){
        Ext.get(e.getTarget()).select('img').each(function(el){
            var w = el.getAttribute('width'), h = el.getAttribute('height'), src = el.getAttribute('src')+' ';
            src = src.replace(new RegExp(this.urlSizeVars[0]+'=[0-9]{1,5}([&| ])'), this.urlSizeVars[0]+'='+w+'$1');
            src = src.replace(new RegExp(this.urlSizeVars[1]+'=[0-9]{1,5}([&| ])'), this.urlSizeVars[1]+'='+h+'$1');
            el.set({src:src.replace(/\s+$/,"")});
        }, this);
        
    },
    onInit: function(){
        Ext.EventManager.on(this.cmp.getDoc(), {
			'mouseup': this.onEditorMouseUp,
			buffer: 100,
			scope: this
		});
    },
    onRender: function() {
        var btn = this.cmp.getToolbar().addButton({
            iconCls: 'x-edit-image',
            handler: this.selectImage,
            scope: this,
            tooltip: {
                title: this.langTitle
            },
            overflowText: this.langTitle
        });
    },
    selectImage: function(){
    	Ext.Msg.alert('填写说明',tip_text);
    }   
});


var cardNav = function(incr){
    var l = Ext.getCmp('card-wizard-panel').getLayout();
    var i = l.activeItem.id.split('card-')[1];
    if(i==0){
    	var c = Ext.ComponentMgr.get('event_text');
    	var value = c.getValue();
    	if(value.length == 0){
    		Ext.Msg.alert('Error','必须输入事件描述');
    		return;
    	}
    }
    var next = parseInt(i, 10) + incr;
    l.setActiveItem(next);
    Ext.getCmp('card-prev').setDisabled(next==0);
    Ext.getCmp('card-next').setDisabled(next==2);
    Ext.getCmp('card-finish').setDisabled(next!=2);
};

c_store= new Ext.data.Store({
	proxy: new Ext.data.MemoryProxy({}),

    reader: new Ext.data.JsonReader({
        //root: 'topics',
        //totalProperty: 'totalCount',
        id: 'id'
    }, [
        {name: 'input_code', mapping: 'input_code'},
        {name: 'normal_input_code', mapping: 'normal_input_code'},
        {name: 'title', mapping: 'title'},
        {name: 'pihao', mapping: 'pihao'},
        {name: 'factory', mapping: 'factory'},
        {name: 'normal_title', mapping: 'normal_title'},
        {name: 'id', mapping: 'id'}
    ])
});
//药品输入ComboBox
Expr.ui.DrugInputComboBox = Ext.extend(Ext.form.ComboBox,{
	constructor:function(config){
		Expr.ui.DrugInputComboBox.superclass.constructor.call(this,config);
	},
	initComponent:function(){
		this.typeAhead=true;
		this.mode= 'local';
        this.forceSelection=true;
        this.triggerAction='all';
        this.emptyText='输入药品...';
        this.selectOnFocus=true;		           		   		    	
  	    this.listWidth=700;
  	    this.tpl= new Ext.XTemplate(
  	  		'<table>',
  		    '<tpl for="."><tr class="search-item">',
  		        '<td>{input_code}</td>',
  		        '<td>{normal_input_code}</td>',
  		        '<td><h3>{title}</h3></td>',
  		        '<td><h3>{normal_title}</h3></td>',
  		        '<td><span>{factory}</span></td>',
  		        '<td>{pihao}</td>',
  		    '</tr></tpl>',
  		    '</table>'	    
  		);
  	  this.itemSelector= 'tr.search-item';
  	 
  	  Expr.ui.DrugInputComboBox.superclass.initComponent.call(this);
	},
	onSelect:function(rd,index){
		   Expr.ui.DrugInputComboBox.superclass.onSelect.call(this,rd,index);
		   select_drug=rd;
		   t=rd.get('title');
		   this.setValue(t);
		   
	   }

});

Ext.reg('druginputcombobox',Expr.ui.DrugInputComboBox);

var drug_input_filter ={
		           displayField:'input_code',
				   store:c_store    	             
}
		       


var xg = Ext.grid;
Ext.grid.dummyData = [{
					   title:'',
					   normal_title:'',
					   factory:'',
					   pihao:'',
					   method:'',
					   begin:'',
					   end:'',
					   reason:'',
					   id:''
					   }];

var drug_reader = new Ext.data.JsonReader(
{id:'id'}, [                                     
     {name: 'title'},                            
     {name: 'normal_title'},                                        
     {name: 'factory'},                             
     {name: 'pihao'},
     {name: 'method'}, 
     {name: 'begin', type: 'date', dateFormat: 'n/j h:ia'},
     {name: 'end', type: 'date', dateFormat: 'n/j h:ia'},
     {name: 'reason'},
     {name: 'id'}
     ]
);


	


//药品输入Grid

Expr.ui.DrugInputGrid = Ext.extend(xg.EditorGridPanel,{
	constructor:function(config){
		Expr.ui.DrugInputGrid.superclass.constructor.call(this,config);
	},
	initComponent:function(){
		var grid = this;
		//console.log(grid);
		var sm2 = new xg.CheckboxSelectionModel({
			_grid:grid,
		    listeners: {
		        // On selection change, set enabled state of the removeButton
		        // which was placed into the GridPanel using the ref config
		        selectionchange: function(sm) {
		            if (sm.getCount()) {
		                this._grid.removeButton.enable();
		            } else {
		               this._grid.removeButton.disable();
		            }
		        }
		    }
		});
		this.sm = sm2;
		this.clicksToEdit =  1;
		this.cm = new xg.ColumnModel([
		                    sm2,
		                    {id:'title',header: "商品名称", width: 40, sortable: true, dataIndex: 'title',
		                    	editor: new Expr.ui.DrugInputComboBox(drug_input_filter)
		                    },
		                    {header: "通用名", width: 40, sortable: true, dataIndex: 'normal_title'},
		                    {header: "生产厂家", width: 40, sortable: true, dataIndex: 'factory'},
		                    {header: "批号", width: 40, sortable: true, dataIndex: 'pihao'},
		                    {header: "用法用量", width: 40, sortable: true, dataIndex: 'method',
		                        editor: new Ext.form.TextField({
		                            allowBlank: false
		                        })
		                    },
		                    {header: "开始时间", width: 40, sortable: true, renderer: Ext.util.Format.dateRenderer('Y/m/d'), dataIndex: 'begin',
		                    	editor: new Ext.form.DateField({
		                        format: 'Y/m/d',
		                        minValue: '01/01/06'
		                    })},
		                    {header: "结束时间", width: 40, sortable: true, renderer: Ext.util.Format.dateRenderer('Y/m/d'), dataIndex: 'end',
		                    	editor: new Ext.form.DateField({
		                        format: 'Y/m/d',
		                        minValue: '01/01/06'      
		                        })},
		                    {header: "用药原因", width: 40, sortable: true, dataIndex: 'reason',
		                     editor: new Ext.form.TextField({
		                            allowBlank: false
		                     })
		                    }
		                    ]);
		
		this.viewConfig = {
	        forceFit:true
	    };
	    this.columnLines =  true;
	    
	    this.tbar=[{
	        text:'增加',
	        tooltip:'添加药品',
	        iconCls:'add',
	        handler : function(){
	            // access the Record constructor through the grid's store
	        	//Ext.Msg.alert('add');
	            var Record= grid.getStore().recordType;
	            var p = new Record({
	            	title: '',
	            	normal_title: '',
	            	factory: '',
	            	pihao: '',
	            	method:'', 
	   		        begin:'',
	   		        end:'',
	   		        reason:''       
	            });
	            grid.stopEditing();
	            n=grid.getStore().getCount();
	            grid.getStore().insert(n, p);
	            grid.startEditing(n, 0);
	        }
	    },'-',{
	        text:'删除',
	        tooltip:'删除选中药品',
	        iconCls:'remove',
	        
	        ref: '../removeButton',
	        disabled: true
	    }];
	  
	    this.height=150;
	    this.frame=true;
	    this.iconCls='icon-grid',
		
		
		Expr.ui.DrugInputGrid.superclass.initComponent.call(this);
		
		
	},
	render : function() {
		Expr.ui.DrugInputGrid.superclass.render.apply(this,arguments)
	        
	    this.on('afteredit', this.onAfterEdit, this)    
	},    
	onAfterEdit:function(e){
		index=e.row;
		col = e.column;
		if(col !=1)
			return;
		rd = this.getStore().getAt(index);
		var helper = function(field){
			rd.set(field,select_drug.get(field));
		}
		helper('normal_title');
		helper('factory');
		helper('pihao');
		helper('id');
		rd.commit();
	},
	getData:function(){
		var store = this.getStore();
		console.log(store);
		var total = store.getCount();
		var result=new Array();
		for(var i=0;i<total;i++){
			result[i]=store.getAt(i).data;
		}
		return result;
	},
	loadData:function(a){
		//console.log(a);
		var store = this.getStore();
		//console.log(store);
		store.loadData(a)
		//store.proxy  = new Ext.data.MemoryProxy(a);
		//store.reload();
		
	}
	
	

});

Ext.reg('druginputgrid',Expr.ui.DrugInputGrid);



Expr.ui.DrugPostWindow = Ext.extend(Ext.Window,{
	constructor:function(config){
		Expr.ui.DrugPostWindow.superclass.constructor.call(this,config);
	},
	initComponent:function(){
		var window= this;
		this.title='药品不良反应上报';
		this.layout='fit';
		this.closable=true;
		this.resizable=true;
		this.plain=true;
		this.modal=true;
		//this.maximized=true;
		this.border=true;
		this.drug_post_form =			
		 new Ext.form.FormPanel(
		{
						id: 'drug_post_form',
						parent:window,
					    frame : true,
						plain : true,
						border : true,
						autoScroll:true,
						layout:'table',
						layoutConfig:{
				   		columns: 6
							},
						items:[
						        {
						        	   layout:'form',
						        	   margins: '0 0 0 0',
						        	   labelWidth : 55,
						        	   style:'border: 1px solid #8db2e3;', 
						        	   items:[
						        	   {
						        		   xtype:'textfield',
						        		   fieldLabel:'患者姓名',
						        		   name:'patient_name',
						        		   id:'patient_name',
						        		   allowBlank: false,
						        		   blankText:"不能为空!",
						        		   width:80
						        	   }
						        	   ]
										
								 },
								 {         
							        	  layout:'form',
							        	  margins: '0 0 0 0',
							        	  labelWidth : 40,
							        	  style:'border: 1px solid #8db2e3;', 
							        	  items:[ {
			            	                  xtype: 'radiogroup',
			            	                  allowBlank: false,
			            	                  blankText:"不能为空!",
			            	                  width:80,
			            	                  id:'sex',
			            	                  fieldLabel: '性别',
			            	                  items: [
			            	                      {boxLabel: '男', name: 'sex', inputValue: 1},
			            	                      {boxLabel: '女', name: 'sex', inputValue: 2}
			            	                     
			            	                  ]
			            	              }]
								  },
								  {  
						        	   layout:'form',
						        	   margins: '0 0 0 0',
						        	   labelWidth : 55,
						        	   style:'border: 1px solid #8db2e3;', 
						        	   border : true,
						        	   items:[{
						        		   xtype:'datefield',
						        		   name:'birthday',
						        		   id:'birthday',
						        		   fieldLabel:'出生年月',
						        		   format:'Ymd',
						        		   allowBlank: false,
						        		   blankText:"不能为空!",
						        		   width:90
						        	   }]		
								  },
								  { 
						        	   layout:'form',
						        	   margins: '0 0 0 0',
						        	   labelWidth : 40,
						        	   style:'border: 1px solid #8db2e3;', 
						        	   border : true,
						        	   items:[{
						        		   xtype:'textfield',
						        		   name:'ethnic',
						        		   id:'ethnic',
						        		   fieldLabel:'民族',
						        		   allowBlank: false,
						        		   blankText:"不能为空!",
						        		   width:80
						        	   }]	
								  },
								  {   
						        	   layout:'form',
						        	   margins: '0 0 0 0',
						        	   labelWidth : 55,
						        	   width:120,
						        	   style:'border: 1px solid #8db2e3;', 
						        	   border : true,
						        	   items:[{
						        		   xtype:'textfield',
						        		   name:'weight',
						        		   id:'weight',
						        		   fieldLabel:'体重(kg)',
						        		   allowBlank: false,
						        		   regex:/[0-9]+/,
						        		   regexText:"必须输入整数!",
						        		   width:35
						        	   }]
								   },
								   {
						        	   
						        	   layout:'form',
						        	   margins: '0 0 0 0',
						        	   labelWidth : 55,
						        	   style:'border: 1px solid #8db2e3;', 
						        	   border : true,
						        	   items:[{
						        		   xtype:'textfield',
						        		   name:'phone',
						        		   id:'phone',
						        		   fieldLabel:'联系方式',
						        		   allowBlank: false,
						        		   blankText:"不能为空!",
						        		   width:100
						        	   }]	
								   },		     

								   {   					     	  
				            	        layout:'form',
				            	        labelWidth : 180,
				            	        style:'border: 1px solid #8db2e3;',
				            	        colspan:3,
				            	        items:
				            	        	  {
				            	                  xtype: 'radiogroup',
				            	                  allowBlank: false,
				            	                  blankText:"请选择!",
				            	                  fieldLabel:'家族药品不良反应/事件情况',
				            	                  items: [
				            	                      {boxLabel: '有',   name: 'jia_zu_qing_kuang', inputValue: 1},
				            	                      {boxLabel: '无',   name: 'jia_zu_qing_kuang', inputValue: 2},
				            	                      {boxLabel: '不详', name: 'jia_zu_qing_kuang', inputValue: 3,checked: true}
				            	                         
				            	                  ]
				            	              }
				            	          
								      },
								      {   					     	  
					            	        layout:'form',
					            	        labelWidth : 180,
					            	        style:'border: 1px solid #8db2e3;',
					            	        colspan:3,
					            	        items:
					            	        	  {
					            	                  xtype: 'radiogroup',
					            	                  allowBlank: false,
					            	                  fieldLabel:'既往药品不良反应/事件情况',
					            	                  blankText:"请选择!",
					            	                  items: [
					            	                      {boxLabel: '有',   name: 'ji_wang_qing_kuang', inputValue: 1},
					            	                      {boxLabel: '无',   name: 'ji_wang_qing_kuang', inputValue: 2},
					            	                      {boxLabel: '不详', name: 'ji_wang_qing_kuang', inputValue: 3,checked: true}
					            	                         
					            	                  ]
					            	              }
					            	          
									    },    

						           {
						        	   layout:'form',
						        	   colspan:2,
						        	   style:'border: 1px solid #8db2e3;',
						        	   labelWidth : 120,
						        	   items:[{
						        		   xtype:'textfield',
						        		   name:'event_name',
						        		   id:'event_name',
						        		   allowBlank: false,
						        		   blankText:"不能为空!",
						        		   fieldLabel:'不良反应/事件名称',
						        		   width:70
						        	   }]
										
								   },
								   {
									   colspan:2,
						        	   labelWidth : 140,
						        	   style:'border: 1px solid #8db2e3;',
						        	   layout:'form',
						        	   border : true,
						        	   items:[{
						        		   xtype:'datefield',
						        		   name:'event_time',
						        		   id:'event_time',
						        		   allowBlank: false,
						        		   blankText:"不能为空!",
						        		   fieldLabel:'不良反应/事件发生时间'
						        		   //width:100
						        	   }]
										
								   },
								   {
									   colspan:2,
						        	   labelWidth : 90,
						        	   style:'border: 1px solid #8db2e3;',
						        	   layout:'form',
						        	   border : true,
						        	   items:[{
						        		   xtype:'textfield',
						        		   name:'patient_id',
						        		   id:'patient_id',
						        		   allowBlank: false,
						        		   blankText:"不能为空!",
						        		   fieldLabel:'病历号/门诊号'
						        		   //width:100
						        	   }]	
								   },
								   
								   {
									   colspan:6,
									   id:'card-wizard-panel',
							    	   style:'border: 1px solid #8db2e3;',
									   layout:'card',
									   activeItem: 0, // index or id
									   bbar: ['->', {
									        id: 'card-prev',
									        text: '&laquo; 上一步',
									        handler: cardNav.createDelegate(this, [-1]),
									        disabled: true
									    },{
									        id: 'card-next',
									        text: '下一步 &raquo;',
									        handler: cardNav.createDelegate(this, [1])
									    },{
									        id: 'card-finish',
									        text: '完成',
									        disabled: true,
									        handler: function(){
									        	 window.saveData();
									        }
									    }
									    ],
									    items: [{
									    	   id:'card-0',
									    	   layout:'fit',
									    	   title:'不良反应/事件过程描述及处理情况',
									    	   height:300,
									           items:[
									                  
									        	       {
									        	        xtype: 'htmleditor',
									        	        name:'event_text',
									        	        id:'event_text',
									        	        height:300,
									        	        allowBlank: false,
									        	        blankText:"不能为空!",
									        	        enableColors: false,
									        	        enableAlignments: false,
									        	        plugins: [ 
									        	                 new Ext.ux.form.HtmlEditor.Image()
									        	                 ],
									        	       value:tip_text
									        	        }
									        	        
									        	    ]	   					        		 		 
									           		
									          },
											  {
												  id:'card-1',
												  layout:'form',
												  items:[{
													  xtype:'druginputgrid',
													  id:'grid1',
													  title:'怀疑用药',
													  name:'huaiyiyongyao',
													  store: new Ext.data.Store({
													        reader: drug_reader,
													        data: xg.dummyData
													   })
												  },
												  {
													  xtype:'druginputgrid',
													  id:'grid2',
													  title:'并用药品',
													  name:'bingyongyaoping',
													  store: new Ext.data.Store({
													        reader: drug_reader,
													        data: xg.dummyData
													   })
												  }
												    ]
											  },
											{
									        id: 'card-2',
									        //layout:'form',
									        height:400,
									        items:[
									               {   						      	 
								        	         title:'不良反应/事件的结果',
								        	         layout:'form',
								        	         labelWidth:125,
								        		     items: {
								        		    	 layout:'column',
								        		    	 //xtype:'fieldset',
								        		    	 fieldLabel:'不良反应/事件结果',
								        		    	 id:'jieguo',
					 					        		 isFormField: true,					 					        		 
								        		    	 items:[
									 					      {
									 					       xtype:'checkbox',
									 					       columnWidth: .07,
									 					       name: 'jieguo',
									 					       boxLabel: '治愈',								 					    
									 					       inputValue: 'zhiyu'
									 					      },{
									 					       columnWidth: .07,
									 					       xtype:'checkbox',
									 					       name: 'jieguo',
									 					       boxLabel: '好转',
									 					       inputValue: 'haozhuan'
									 					      },
									 					      {
									 					    	     columnWidth: .10,
									 					    	     xtype:'checkbox',
										 					         name: 'jieguo',
										 					         boxLabel: '有后遗症',
										 					         inputValue: 'houyizheng'
										 					   },
										 					   {
										 					    	  columnWidth: .18,										 					    	
										 					    	  layout:'form',
										 					    	  labelWidth : 35,
										 					    	  isFormField: true,
										 					    	  items:[{
										 					    	  xtype:'textfield',
										 					    	  name:'jieguo_biaoxian_t',
										 					    	  id:'jieguo_biaoxian_t',
										 			        		  fieldLabel:'表现',
										 			        		  validator : function(){
								 					        			 //console.log('in validator');
								 					        			 return true;
								 					        			 return '请选择';
								 					        	      },
										 			        		  width:80}]
											 					},
										 					    {
										 					    		 columnWidth: .07,
										 					    		 xtype:'checkbox',
											 					         name: 'jieguo',
											 					         boxLabel: '死亡',
											 					         inputValue: 'siwang'
											 					 },
											 					  {
											 					    	columnWidth: .22,	 					    	  
											 					    	 layout:'form',
											 					    	  labelWidth : 55,
											 					    	  items:[{
											 					    	  xtype:'textfield',
											 					    	  name:'jiguo_zhijiesiyin',
											 					    	  id:'jiguo_zhijiesiyin',
											 			        		  fieldLabel:'直接死因',
											 			        		 width:80}]
												 					   },
												 					  {
												 						  columnWidth: .25, 
												 						  //width:300,
												 					      
												 					      layout:'form',
												 					     labelWidth : 55,
												 					      items:{ 
												 					        	xtype:'datefield',
												 					        	name:'jiguo_siwangshijian',
													 					    	id:'jiguo_siwangshijian',
												 					            fieldLabel:'死亡时间',
												 					            width:90
												 					       }
													 				  }	]
								        		                }					 					         				        		   				        	          
									               },{
									            	   title:'原患疾病',
									            	   layout:'form',
									            	   items:[
									            	          {
									            	            xtype:'textfield',
									            	            name:'yuanyoujibing',
									            	            id:'yuanyoujibing',
									            	            fieldLabel:'原患疾病',
									            	            allowBlank: false,
									            	            vtypeText:"不能为空!",
									            	            width:300
							 			        	          },{				        		   
							 					        		   fieldLabel:'对原患疾病影响',
							 					        		   layout:'column',
							 					        		   isFormField: true,
							 					        		   //width:180,
							 					        		   defaultType: 'checkbox',
							 					        		   items: [
							 						 					      {
							 						 					       columnWidth: .10,
							 						 					       name: 'yingxiang',
							 						 					       boxLabel: '不明显',
							 						 					       inputValue: 'bumingxian'
							 						 					      },{
							 						 					       columnWidth: .10,
							 						 					       name: 'yingxiang',
								 						 					   boxLabel: '病程延长',
								 						 					   inputValue: 'yanchang'
							 						 					      },{
							 						 					       columnWidth: .10,
							 						 					       name: 'yingxiang',
								 						 					   boxLabel: '病情加重',
								 						 					   inputValue: 'jiazhong'
							 							 					   },{
							 							 					   columnWidth: .12,
								 						 					   name: 'yingxiang',
									 						 				   boxLabel: '导致后遗症',
									 						 				   inputValue: 'houyizheng'
								 							 				   },{
								 							 					   columnWidth: .18,
								 							 					   layout:'form',
								 							 					   xtype:'panel',
								 							 					   isFormField: true,
								 							 					   labelWidth : 35,
								 							 					   items:{
								 							 					   xtype:'textfield',
								 							 					   fieldLabel:'表现',
								 							 					   name:'yingxiang_biaoxian',
								 							 					   width:80}
								 							 				   },{	
								 							 					 columnWidth: .10,
								 							 					 name: 'yingxiang',
										 						 				 boxLabel: '导致死亡',
										 						 				 inputValue: '死亡'
								 							 				   }
								 							 			]   			 	
							 					        	   }
									            	         ]
									               },{
									            	   title:'相关报道',
									            	   layout:'column',
									            	   
									            	   items:[
									            	          {
									            	        	  columnWidth: .50,
									            	        	  layout:'form',
									            	        	  labelWidth : 220,
									            	        	  items:
									            	        	  {
									            	                  xtype: 'radiogroup',
									            	                  fieldLabel: '国内有无类似不良反应(包括文献报道)',
									            	                  allowBlank: false,
									            	                  items: [
									            	                      {boxLabel: '有', name: 'guoneibaodao', inputValue: 1},
									            	                      {boxLabel: '无', name: 'guoneibaodao', inputValue: 2},
									            	                      {boxLabel: '不详', name: 'guoneibaodao', inputValue: 3,checked: true}
									            	                     
									            	                  ]
									            	              }
									            	          },{
									            	        	  columnWidth: .50,
									            	        	  layout:'form',
									            	        	  labelWidth : 220,
									            	        	  items:
									            	        	  {
									            	                  xtype: 'radiogroup',
									            	                  fieldLabel: '国外有无类似不良反应(包括文献报道)',
									            	                  allowBlank: false,
									            	                  items: [
									            	                      {boxLabel: '有', name: 'guowaibaodao', inputValue: 1},
									            	                      {boxLabel: '无', name: 'guowaibaodao', inputValue: 2},
									            	                      {boxLabel: '不详', name: 'guowaibaodao', inputValue: 3,checked: true}
									            	                     
									            	                  ]
									            	              }
									            	          }
									            	          ]
									            	   
									               },{
									            	   title:'关联性评价',
									            	   style:'border: 1px solid #8db2e3;',
									            	   layout:'form',
									            	   height:150,
									            	   items:[
									            	          {
									            	        	  
									            	        	  layout:'form',
									            	        	  labelWidth : 220,
									            	        	  items:
									            	        	  {
									            	                  xtype: 'checkboxgroup',
									            	                  fieldLabel: '报告人',
									            	                  items: [
									            	                      {boxLabel: '肯定', name: 'baogaoren', inputValue: 1},
									            	                      {boxLabel: '很可能', name: 'baogaoren', inputValue: 2},
									            	                      {boxLabel: '可能', name: 'baogaoren', inputValue: 3},
									            	                      {boxLabel: '可能无关', name: 'baogaoren', inputValue: 4},
									            	                      {boxLabel: '待评价', name: 'baogaoren', inputValue: 5},
									            	                      {boxLabel: '无法评价', name: 'baogaoren', inputValue: 6}
									            	                     
									            	                  ]
									            	              }
									            	          },
				                                              {
									            	        	  
									            	        	  layout:'form',
									            	        	  labelWidth : 220,
									            	        	  items:
									            	        	  {
									            	                  xtype: 'checkboxgroup',
									            	                  fieldLabel: '报告单位',
									            	                  items: [
									            	                      {boxLabel: '肯定', name: 'baogaodanwei', inputValue: 1},
									            	                      {boxLabel: '很可能', name: 'baogaodanwei', inputValue: 2},
									            	                      {boxLabel: '可能', name: 'baogaodanwei', inputValue: 3},
									            	                      {boxLabel: '可能无关', name: 'baogaodanwei', inputValue: 4},
									            	                      {boxLabel: '待评价', name: 'baogaodanwei', inputValue: 5},
									            	                      {boxLabel: '无法评价', name: 'baogaodanwei', inputValue: 6}    
									            	                  ]
									            	              }
									            	          },{
									            	        	  layout:'form',
									            	        	  labelWidth : 220,
									            	        	  items:
									            	        	  {
									            	                  xtype: 'checkboxgroup',
									            	                  fieldLabel: '省级药品不良反应监测机构',
									            	                  items: [
									            	                      {boxLabel: '肯定', name: 'shengjijigou', inputValue: 1},
									            	                      {boxLabel: '很可能', name: 'shengjijigou', inputValue: 2},
									            	                      {boxLabel: '可能', name: 'shengjijigou', inputValue: 3},
									            	                      {boxLabel: '可能无关', name: 'shengjijigou', inputValue: 4},
									            	                      {boxLabel: '待评价', name: 'shengjijigou', inputValue: 5},
									            	                      {boxLabel: '无法评价', name: 'shengjijigou', inputValue: 6}					            	                     
									            	                  ]
									            	              }
									            	          }
									            	          ,{					            	        	  
									            	        	  layout:'form',
									            	        	  labelWidth : 220,
									            	        	  items:
									            	        	  {
									            	                  xtype: 'checkboxgroup',
									            	                  fieldLabel: '国家药品不良反应监测机构',
									            	                  items: [
									            	                      {boxLabel: '肯定', name: 'guojiajigou', inputValue: 1},
									            	                      {boxLabel: '很可能', name: 'guojiajigou', inputValue: 2},
									            	                      {boxLabel: '可能', name: 'guojiajigou', inputValue: 3},
									            	                      {boxLabel: '可能无关', name: 'guojiajigou', inputValue: 4},
									            	                      {boxLabel: '待评价', name: 'guojiajigou', inputValue: 5},
									            	                      {boxLabel: '无法评价', name: 'guojiajigou', inputValue: 6}					            	                     
									            	                  ]
									            	              }
									            	          }
									            	          ]					            	   
									               }
									               ]
									    }]
								   }
						           ]
				}//form
		);
		this.items = this.drug_post_form;
		
		
		
		
		Expr.ui.DrugPostWindow.superclass.initComponent.call(this);
	},
	loadPatientData:function(patient_id){
		var window = this;
		
		var load_myMask = new Ext.LoadMask(Ext.getBody(), {  
            msg : "正在加载病人信息. Please wait...."  
        }); 
		var callback = function(response, e){
			window.enable();
			if (true === e.status) {
				if(response.success == true){
					var form = window.drug_post_form.form;
					var patient=response.patient;
					form.findField('patient_name').setValue(patient.name);
					
					if(patient.sex == '男')
						form.findField('sex').setValue(1);
					else
						form.findField('sex').setValue(2);
					form.findField('birthday').setValue(patient.birthday);
					form.findField('ethnic').setValue(patient.ethnic);
					form.findField('phone').setValue(patient.phone);
					form.findField('patient_id').setValue(patient.id);
					
				}else{
					Ext.Msg.alert('Error','读取病人信息错误!');
				}
				
			}
			
			load_myMask.hide();
		};
		   
		load_myMask.show();
		window.disable();
		Patient_Filter.patient_info_by_id(patient_id,callback);
	},
	initBlankWindowData:function(patient_id){
		var window = this;
		this.patient_id = patient_id;
		var load_myMask = new Ext.LoadMask(Ext.getBody(), {  
            msg : "正在加载所用药品. Please wait...."  
        }); 
		var drug_callback = function(response, e){
			window.enable();
			if (true === e.status) {
				c_store.proxy  = new Ext.data.MemoryProxy(response.data);
				c_store.reload();
			}
			
			load_myMask.hide();
			window.loadPatientData(patient_id);
		};
		   
		  load_myMask.show();
		  window.disable();
		  
		  Drug_Filter.patient_used_drug_list(patient_id,drug_callback);
		
	},
	loadData:function(report){
		var window = this;
		var form = this.drug_post_form.form;
		
		var load_myMask = new Ext.LoadMask(Ext.getBody(), {  
            msg : "正在加载数据. Please wait...."  
        }); 
		
		var callback = function(response, e){
			window.enable();
			if (true === e.status) {
				//console.log(response.report)
				var pid= response.report.fields.patient_id;
				window.report_id = response.report.id;
				form.setValues(response.report.fields)
			}
			
			load_myMask.hide();
			if(pid !=undefined){
				window.initBlankWindowData(pid);
				
				var g = Ext.ComponentMgr.get('grid1');
				g.loadData(response.report.drugs[0]);
				var g = Ext.ComponentMgr.get('grid2');
				g.loadData(response.report.drugs[1]);
			}
			
		};
		load_myMask.show();
		window.disable();
		Drug_Filter.drug_report_by_id(report,callback)
		  
	},
	saveData:function(){
		var window = this;
		var form = this.drug_post_form.form;
		if(form.isValid()){
			var values = form.getValues();
			if(values.jieguo == undefined){
				Ext.Msg.alert('Error','请选择不良反应结果');
				return;
			}
			if(values.yingxiang == undefined){
				Ext.Msg.alert('Error','请选择对原有疾病的影响');
				return;
			}
			var drugs = new Array();
			drugs[0]=Ext.ComponentMgr.get('grid1').getData();
			drugs[1]=Ext.ComponentMgr.get('grid2').getData();
			
			var load_myMask = new Ext.LoadMask(Ext.getBody(), {  
	            msg : "正在上传数据. Please wait...."  
	        }); 
			load_myMask.show();
			window.disable();
			
			//console.log(this.report_id);
			Drug_Filter.drug_report_merge(this.patient_id,drugs,values,this.report_id,function(response, e){
				load_myMask.hide();
				window.enable();
				if (true === e.status) {
					if(response.success==true){
						Ext.Msg.alert('Information','提交成功')
						window.close();
					}else{
						Ext.Msg.alert('Error','提交失败')
					}
				}else{
					Ext.Msg.alert('Error','提交失败')
				}
				
				
			});
			
		}else{
			Ext.Msg.alert('Error','请正确输入必要的基本数据');
		}
	}
	
});